<template>
	<view class="toupiaodiaoyan-page">
		<view  class="flex flex-column bgcolor1 border-bottom p-2 msgitem"
			v-for="(item,index) in dataList"  
			:key="index"  
			@click="navTo(item)">
			<view class="flex align-center">
				<image style="width: 20px;height: 20px;" src="/static/images/toupiao.png" mode="widthFix"></image>
				<text class="fs-32 ftcolor1 ml-2">{{item.info}}</text>
			</view>
			<view  class="flex align-center justify-between my-1">
				<view class="flex align-center">
					<u-icon name="account" size="18px"></u-icon>
					<text class="ftcolor2 fs-24 ml-1">{{item.release_admin.name}}</text>
				</view>
				<view class="flex align-center">
					<image style="width: 15px;height: 15px;" src="/static/images/region_icon.png" mode="widthFix"></image>
					<text class="ftcolor2 fs-24 ml-1">{{item.regions.name}}</text>
				</view>
			</view>
			<view class="flex align-center justify-between">
			 <view class="flex align-center">
				<u-icon name="clock" size="15px"></u-icon>
			 	<text class="ftcolor1 fs-24 ml-1">{{item.end_time}}</text>
			 </view>
			 <view class="flex align-center">
			 	<text class="ftcolor4 fs-24">投票结果：</text>
			 	<text class="color1 fs-24">{{item.statusText}}</text>
			 </view>
			</view>
		</view>
		<view class="text-center py-3" v-if="this.tempList.length === 15"><text class="fs-24 ftcolor2"
				@click="clickMore">查看更多</text></view>
		<noneBox v-if="dataList.length === 0"></noneBox>
	</view>
</template>

<script>
	import serviceApi from '@/api/serviceApi.js'
	export default {
		data() {
			return {
				dataList:[],
				tempList:[],
				page:1,
			}
		},
		onShow() {
			this.ballot_list()
		},
		methods: {
			ballot_list(){
				serviceApi.ballot_list({page:this.page,limit:15}).then(res => {
					this.tempList = res.data
					if (this.page === 1) {
						this.dataList = res.data
					} else {
						this.dataList = this.dataList.concat(res.data)
					}
					this.dataList.forEach(i => {
						const end_time = new Date(i.end_time).getTime()
						const nowtime = new Date().getTime()
						i.statusText = nowtime > end_time?'结束':'投票中'
					})
				})
			},
			clickMore() {
				if (this.tempList.length === 15) {
					this.page++
					this.ballot_list()
				}
			},
			navTo(item){
				uni.setStorageSync('toupiaoinfo',item)
				uni.navigateTo({
					url:'/pages/service/toupiaodiaoyan-details'
				})
			},
		}
	}
</script>

<style lang="scss">
.toupiaodiaoyan-page{
	.color1{
		color:#ff9900;
	}
	.color2{
		color:#18b566;
	}
}
</style>
